package com.cn.studey.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.cn.studey.entity.User;
import com.cn.studey.mapper.UserMapper;
import com.cn.studey.service.UserService;
import com.cn.studey.utils.JwtTokeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author mjy
 * @date 2021/12/29
 * @description
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserInfoByAccountAndPwd(String account, String pwd) {

        return new LambdaQueryChainWrapper<>(userMapper)
                .eq(User::getAccount, account)
                .eq(User::getPwd, pwd)
                .one();
    }

    @Override
    public Integer updateUserById(User newUser) {
        return userMapper.updateById(newUser);
    }

    @Override
    public Long getUserId(String token) {
        Long userId = JwtTokeUtil.getValue(token, "userId", Long.class);
        return userId;
    }
}
